/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Sooraj Bhatt 
 												
Class							:				RunBot 
 
Function						: 				Provides a Launcher for Running the 
												the basic Wargus agent along with the behavior 
												adaptation system
****************************************************************************/
package base;


import cbr.episodicCBR.EpisodicCBR;
import trace.Testtrace;
import behavioradaptation.reasoner.Reasoner;

public class RunBotTrace {
	 public static void main(final String[] args) {
	    	
	    	System.out.println("RunBot started...");
			Testtrace t = new Testtrace();
			// Read a serialized trace corresponding nw04-lite map
			t.readSerialize("game-trace.dat");
			// Reasoner is the main class for behavior adaptation system
			EpisodicCBR cbr = new EpisodicCBR();
			Reasoner r;			
			try {
				r = new Reasoner(t.tr, cbr);			
				// Reset the case base after the modification
				r.m_cbr.resetBehaviors();	
				// identify the failures from the trace and fix them 
				r.reason(t.tr);
			} catch (Exception e) {
				e.printStackTrace();
			}
	        try {
	        	// r.m_cbr.getCaseBase().loadCases("cases/inferred-cases2.xml");
	        	ProxyBot pb = null;
			    if (args.length > 1 && args[1].equals("-debug")) {
			    	pb = new ProxyBot("localhost", true);
			    	new Thread(pb).start();
			    } else {
			    	pb = new ProxyBot("localhost", false);
		            new Thread(pb).start();
			    }
	            new Thread(new WargusmainTrace(pb, cbr)).start();
	        }
	        catch (Throwable thr) {
	            System.err.println("usage: java wsm.RunBot <entityName>");
	            System.err.println("e.g.   java wsm.RunBot wargusagents.Demo\n");
	            thr.printStackTrace();
	            System.exit(1);
	        }
	       
	    }
}
